package com.yj.web.dao.mapper;

import com.yj.web.dao.po.admin.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface MessageMapper {
    //短信
    @Select("select * from message where instr(message.receiverStr, #{phone}) or receiverStr = 'all' order by message.id desc limit #{size} offset #{offset}")
    public List<Message> listMessageByReceiver(@Param("phone") String phone, @Param("offset") int offset, @Param("size") int size);

    @Select("select * from message order by message.id desc limit #{size} offset #{offset}")
    public List<Message> listMessage(@Param("offset") int offset, @Param("size") int size);

    @Select("select count(*) from message where instr(message.receiverStr, #{phone}) or receiverStr = 'all'")
    public int countMessageByReceiver(@Param("phone") String phone);

    @Select("select count(*) from message")
    public int countMessage();

    @Insert("insert into message (receiverStr, number, content, create_at, complete_at, status, type) values (#{message.receiverStr}, #{message.number}, #{message.content}, now(), #{message.complete_at}, #{message.status}, #{message.type})")
    @Options(useGeneratedKeys = true, keyProperty = "message.id")
    public long insertMessage(@Param("message") Message message);

    @Update("update message set status=1 where id = #{id} and status=0")
    public boolean updateMessage(@Param("id") long id);
}
